<?php
if(preg_match("/lottou/", $_SERVER["DOCUMENT_ROOT"])){
	include_once($_SERVER["DOCUMENT_ROOT"]."/config.inc.php");
	include_once($_SERVER["DOCUMENT_ROOT"]."/db.inc.php");
	$strWeb = trim($_data["Web"]);
}else{
	$_SERVER["DOCUMENT_ROOT"] = "/home/share/www/SourceSite-utf8/secure";
	include_once("/home/share/www/SourceSite-utf8/secure/config.inc.php");
	$strWeb = trim($_data["Web"]);
	include("/home/share/www/".$strWeb."/secure/db.inc.php");
}

$strType = trim($_data["Type"]);
$strGroup = trim($_data["Group"]);
$isShowSQL = ($_data["isShowSQL"] == "Y")?true:false;
$intVIP = null;
$intStatus = null;
if($_data["Vip"] != "")$intVIP = (int)$_data["Vip"];
if($_data["Status"] != "")$intStatus = (int)$_data["Status"];

function outPutXML($strCon){
	header("Content-Type: text/xml");
	print "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n";
	print "<MRoot>\n";
	print $strCon;
	print "</MRoot>";
	exit();
}

function ErrOutPutXML($strErr){
	header("Content-Type: text/xml");
	print "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n";
	print "<MRoot>\n";
	print "\t<Error>".$strErr."</Error>\n";
	print "</MRoot>";
	exit();
}

$strCheckData = "";//$objMember -> SkypeAcc;
switch(strtolower($strType)){
	case "email":
		$strCheckData = "Email";
		break;

	case "qq":
		$strCheckData = "QQNum";
		break;

	case "msn":
		$strCheckData = "MSN";
		break;

	case "mphone":
		$strCheckData = "MPhone";
		break;

	case "skype":
	default:
		$strType = "Skype";
		$strCheckData = "SkypeAcc";
		break;
}

$strSQL = "select a.*, a.".$strCheckData." as CommData, b.GroupName_1 as GName from `bet_Member` a, `bet_MemberGroup` b, `bet_Authentication` c where a.".$strCheckData." != '' and a.MemberGroup in (".$strGroup.") and a.MemberGroup = b.ID and b.ID < 10 and a.ID = c.UserID and c.MType = '".$strCheckData."' and c.isCheck = 1 ";
if($intVIP !== null)$strSQL .= " and a.SpGroup = ".$intVIP;
if($intStatus !== null)$strSQL .= " and a.isLock = ".$intStatus;

if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
	if($isShowSQL){
		ErrOutPutXML("Find User Data Error (".$strSQL.")");
	}else{
		ErrOutPutXML("Find User Data Error");
	}
}

//找不到帳號密碼
if(PMA_mysql_num_rows($RS) == 0){
	if($isShowSQL){
		ErrOutPutXML("No User Data (".$strSQL.")");
	}else{
		ErrOutPutXML("No User Data");
	}
}

$strUData = "";
while($objUser = PMA_mysql_fetch_object($RS)){
	$strGroup = $objUser -> GName;
	$strSpGroup = $objUser -> SpGroup == 1?"VIP":"一般";
	$strStatus = "OK";
	switch($objUser -> isLock){
		case 1:
			$strStatus = "停用中";
			break;

		case 2:
			$strStatus = "停押中";
			break;
	}

	$strCommData = $objUser -> CommData;
	if($strCheckData == "MPhone"){
		$arrTmp = explode("-", $objUser -> CommData);
		$strCommData = "+".$arrTmp[0].$arrTmp[1];
	}

	$strUData .= "\t<UData>\n";
	$strUData .= "\t\t<Acc>".$objUser -> Account."</Acc>\n";
	$strUData .= "\t\t<CommData>".$strCommData."</CommData>\n";
	$strUData .= "\t\t<Group>".$strGroup."</Group>\n";
	$strUData .= "\t\t<SpGroup>".$strSpGroup."</SpGroup>\n";
	$strUData .= "\t\t<Status>".$strStatus."</Status>\n";
	$strUData .= "\t</UData>\n";
}

outPutXML($strUData);
?>